<template>
  <el-row style="height: 100%">
    <div id="main1" style="height: 100%"></div>
  </el-row>
</template>

<script>
import * as echarts from 'echarts';
import {
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components';
import {
  BarChart
} from 'echarts/charts';
import {
  CanvasRenderer
} from 'echarts/renderers';

echarts.use(
    [ToolboxComponent, TooltipComponent, GridComponent, LegendComponent, BarChart, CanvasRenderer]
);

export default {
  name: "ColumnCharts",
  data() {
    return {
      msg: 'Welcome to Your Vue.js App',
      option: {
        title: {
          text: '订单总量(按食品)'
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            }
          }
        ]
      }
    }
  },
  mounted() {
    this.drawLine()
  },
  methods: {
    drawLine() {
      this.axios.get('/food_column_chart',{
        headers: {
          'content-type':'application/json',
          'token':this.$cookies.get("token")
        }
      }).then((res)=>{
        if (res.data.code == 200) {
          let name_list = res.data.data.name
          let num_list = res.data.data.num_list
          this.option.series[0].data = num_list
          this.option.xAxis.data = name_list
          var chartDom = document.getElementById('main1');
          var myChart = echarts.init(chartDom);
          this.option && myChart.setOption(this.option);
        }
      }).catch((res)=>{
        console.log(res);
      })
    }
  }
}
</script>

<style scoped>


</style>